package com.zhixiang.xaec.action.safebase.safemeeting;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.entity.TreeObj;
import com.zhixiang.core.util.BeanUtil;
import com.zhixiang.core.util.YearGridCrud;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.safebase.safemeeting.MeetInformation;
import com.zhixiang.xaec.service.safebase.safemeeting.MeetInformationService;


@Controller
@Scope("prototype")
public class MeetInformationAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4855262087107708145L;

	private MeetInformation meetInformation;
	
	@Autowired
	private MeetInformationService meetInformationService;

	public void setMeetInformation(MeetInformation meetInformation) {

		this.meetInformation = meetInformation;
	}

	public MeetInformation getMeetInformation() {

		return meetInformation;
	}

	public String list() {

		QueryFilter localQueryFilter = new QueryFilter(getRequest());
		List<MeetInformation> localList = this.meetInformationService.getAll(localQueryFilter);
		setSuccess(true);
		setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
		// 返回结果集
		setResult(localList);
		return SUCCESS;
	}

	public String get() {
		String id = getRequest().getParameter("id");
		if (!"".equals(id) && id != null) {
			setResult(meetInformationService.get(Long.valueOf(id)));
		}
		return SUCCESS;
	}

	public String delete() {
		try {
			String[] ids = getRequest().getParameterValues("ids");
			meetInformationService.delete(ids);
		} catch (Exception e) {
			setMsg("删除失败");
			setSuccess(false);
		}
		return SUCCESS;
	}

	public String save() {
		try {
			if(meetInformation.getId()!=null){
				MeetInformation mf = meetInformationService.get(meetInformation.getId());
				BeanUtil.copyNotNullProperties(mf, meetInformation);
				meetInformationService.save(mf);
			}else{
				meetInformationService.save(meetInformation);
			}
		} catch (Exception e) {
			setMsg("保存失败");
			setSuccess(false);
		}

		return SUCCESS;
	}

	public String treeLoad() {
		List<TreeObj> treeList = YearGridCrud.treeLoad();
		if (treeList != null) {
			outJsonString(new Gson().toJson(treeList));
		}
		return SUCCESS;
	}

}
